unit Visao1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, MVCInterfaces, Multiplicacao;

type
  TCalcEvent = procedure of object;

type
  TVisao = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    EdtValor1: TEdit;
    EdtValor2: TEdit;
    Label3: TLabel;
    Label4: TLabel;
    EdtSolucao: TEdit;
    BtnCalcular: TButton;
    procedure BtnCalcularClick(Sender: TObject);
  private
    { Private declarations }
    FModel: TModeloMultiplicacao;
    FFazCalculo: TCalcEvent;

    procedure SetModelo(const Valor: TModeloMultiplicacao);
    procedure SetFazCalculo( const Valor: TCalcEvent);
  public
    { Public declarations }
    procedure Initialize;
    procedure ModelChanged;

    property Model: TModeloMultiplicacao read FModel write SetModelo;
    property FazCalculo: TCalcEvent read FFazCalculo write SetFazCalculo;
  end;

var
  Visao: TVisao;

implementation

//uses MVCInterfaces, Multiplicacao;

{$R *.dfm}

{ TVisao }

procedure TVisao.Initialize;
begin
  EdtValor1.Text := FloatToStr(Model.Valor1);
  EdtValor2.Text := FloatToStr(Model.Valor2);
  EdtSolucao.Text := FloatToStr(Model.Solucao);
end;

procedure TVisao.ModelChanged;
begin
  Initialize;
end;

procedure TVisao.SetFazCalculo(const Valor: TCalcEvent);
begin
  FFazCalculo := Valor;
end;

procedure TVisao.SetModelo(const Valor: TModeloMultiplicacao);
begin
  FModel := Valor;
end;

procedure TVisao.BtnCalcularClick(Sender: TObject);
begin
  Model.Valor1 := StrToFloat(EdtValor1.Text);
  Model.Valor2 := StrToFloat(EdtValor2.Text);

  if(Assigned(FazCalculo))then
  begin
    FazCalculo;
  end;
end;

end.
